package com.apes.fn.fico.reimbursement.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by cyy on 2022/9/23 09:36
 * 交易流水使用明细
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = TransactionFlowDetails.CONST_TABLE_NAME)
public class TransactionFlowDetails extends BaseModel {

    public static final String CONST_TABLE_NAME = "fn_transaction_flow_details";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "交易流水使用明细", padding = 7)
    @Comment("交易流水使用明细编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="transaction_flow_id", referencedColumnName="id")
    @Comment("交易流水编码")
    private TransactionFlow transactionFlow;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "transaction_date")
    @Comment("交易日期")
    private Date transactionDate;

    @Name
    @NonNull
    @Column(name = "transaction_flow_num")
    @Comment("交易流水号")
    private String transactionFlowNum;

    @Column(name = "receipt_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("收款金额")
    private double receiptAmount = 0;

    @Column(name = "amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("付款金额")
    private double amount = 0;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "use_date")
    @Comment("使用日期")
    private Date useDate;

    @Column(name = "source_business_type", length = 125)
    @Comment("使用单据")
    private String sourceBusinessType;

    @Column(name = "source_business_key", length = 64)
    @Comment("使用单号")
    private String sourceBusinessKey;

    @Column(name = "used_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("使用金额")
    private double usedAmount = 0;


}
